package com.pro.controller;
//商品分类 控制层
import com.pro.pojo.*;
import com.pro.service.SyStatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@RequestMapping(value = "/SyStatistical")
@Controller
public class SyStatisticalController {
    @Autowired
    private SyStatisticalService syStatisticalService;
    //商品点击量
    @RequestMapping(value = "/getSyProductCategroys")
    @ResponseBody
    public JsonData getSyProductCategroys(){
        List<SyProductCategroy> syProductCategroys = syStatisticalService.getSyProductCategroys();
        return syProductCategroys != null ? JsonData.buildSuccess(syProductCategroys) : JsonData.buildError("服务器出错了");
    }
    //商品收藏量
    @RequestMapping(value = "/getSyProductCategroysColl")
    @ResponseBody
    public JsonData getSyProductCategroysColl(){
        List<SyProductCategroy> syProductCategroys = syStatisticalService.getSyProductCategroysColl();
        return syProductCategroys != null ? JsonData.buildSuccess(syProductCategroys) : JsonData.buildError("服务器出错了");
    }
    //课程点赞量
    @RequestMapping(value = "/getCourseClass")
    @ResponseBody
    public JsonData getCourseClass(){
        List<JsCourseClass> courseClass = syStatisticalService.getCourseClass();
        return courseClass != null ? JsonData.buildSuccess(courseClass) : JsonData.buildError("服务器出错了");
    }

    //课程分享量
    @RequestMapping(value = "/getCourseClassShare")
    @ResponseBody
    public JsonData getCourseClassShare(){
        List<JsCourseClass> courseClass = syStatisticalService.getCourseClassShare();
        return courseClass != null ? JsonData.buildSuccess(courseClass) : JsonData.buildError("服务器出错了");
    }

    //课程收藏量
    @RequestMapping(value = "/getCourseClassColl")
    @ResponseBody
    public JsonData getCourseClassColl(){
        List<JsCourseClass> courseClass = syStatisticalService.getCourseClassColl();
        return courseClass != null ? JsonData.buildSuccess(courseClass) : JsonData.buildError("服务器出错了");
    }

    //课程预览量
    @RequestMapping(value = "/getCourseClassLook")
    @ResponseBody
    public JsonData getCourseClassLook(){
        List<JsCourseClass> courseClass = syStatisticalService.getCourseClassLook();
        return courseClass != null ? JsonData.buildSuccess(courseClass) : JsonData.buildError("服务器出错了");
    }
    //微圈点赞量
    @RequestMapping(value = "/getMicrocircle")
    @ResponseBody
    public JsonData getMicrocircle(){
        List<JsActicleCategroy> microcircles = syStatisticalService.getMicrocircle();
        return microcircles != null ? JsonData.buildSuccess(microcircles) : JsonData.buildError("服务器出错了");
    }
    //微圈分享量
    @RequestMapping(value = "/getMicrocircleShare")
    @ResponseBody
    public JsonData getMicrocircleShare(){
        List<JsActicleCategroy> microcircles = syStatisticalService.getMicrocircleShare();
        return microcircles != null ? JsonData.buildSuccess(microcircles) : JsonData.buildError("服务器出错了");
    }
    //微圈收藏量
    @RequestMapping(value = "/getMicrocircleColl")
    @ResponseBody
    public JsonData getMicrocircleColl(){
        List<JsActicleCategroy> microcircles = syStatisticalService.getMicrocircleColl();
        return microcircles != null ? JsonData.buildSuccess(microcircles) : JsonData.buildError("服务器出错了");
    }
    //微圈点击量
    @RequestMapping(value = "/getMicrocircleLook")
    @ResponseBody
    public JsonData getMicrocircleLook(){
        List<JsActicleCategroy> microcircles = syStatisticalService.getMicrocircleLook();
        return microcircles != null ? JsonData.buildSuccess(microcircles) : JsonData.buildError("服务器出错了");
    }
    //查询所有课程订单
    @RequestMapping(value = "/getAllcourseCountShowId")
    @ResponseBody
    public JsonData getAllcourseCountShowId(){
        List<JsCourse> allcourseCountShowId = syStatisticalService.getAllcourseCountShowId();
        return allcourseCountShowId != null ? JsonData.buildSuccess(allcourseCountShowId) : JsonData.buildError("服务器出错了");
    }
    //查询所有课程订单
    @RequestMapping(value = "/getAllProductShowId")
    @ResponseBody
    public JsonData getAllProductShowId(){
        List<JsCourse> allProduct = syStatisticalService.getAllProductShowId();
        return allProduct != null ? JsonData.buildSuccess(allProduct) : JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getCoursePrimary")
    @ResponseBody
    public JsonData getCoursePrimary(){
        List<JsCourseClass> coursePrimary = syStatisticalService.getCoursePrimary();
        return coursePrimary != null ? JsonData.buildSuccess(coursePrimary) : JsonData.buildError("服务器出错了");
    }

    //查询关键字
    @RequestMapping(value = "/getSearchKeyWords")
    @ResponseBody
    public JsonData getSearchKeyWords(){
        List<JsSearchKeywords> searchKeyWords = syStatisticalService.getSearchKeyWords();
        return searchKeyWords != null ? JsonData.buildSuccess(searchKeyWords) : JsonData.buildError("服务器出错了");
    }

    //查询前台用户人数
    @RequestMapping(value = "/getBeforeUser")
    @ResponseBody
    public JsonData getBeforeUser(){
        Integer beforeUser = syStatisticalService.getBeforeUser();
        return beforeUser != null ? JsonData.buildSuccess(beforeUser) : JsonData.buildError("服务器出错了");
    }

    //查询后台用户人数
    @RequestMapping(value = "/getBackstageUser")
    @ResponseBody
    public JsonData getBackstageUser(){
        Integer backstageUser = syStatisticalService.getBackstageUser();
        return backstageUser != null ? JsonData.buildSuccess(backstageUser) : JsonData.buildError("服务器出错了");
    }

    //查询课程交易数量
    @RequestMapping(value = "/getSaleNum")
    @ResponseBody
    public JsonData getSaleNum(){
        List<JsCourseClass> saleNum = syStatisticalService.getSaleNum();
        return saleNum != null ? JsonData.buildSuccess(saleNum) : JsonData.buildError("服务器出错了");
    }

    //查询无消费记录的人员
    @RequestMapping(value = "/getBeforPon")
    @ResponseBody
    public JsonData getBeforPon(){
        List<JsBeforeUser> beforPon = syStatisticalService.getBeforPon();
        return beforPon != null ? JsonData.buildSuccess(beforPon) : JsonData.buildError("服务器出错了");
    }

    //查询前端用户创建月份
    @RequestMapping(value = "/getBeforeBydate")
    @ResponseBody
    public JsonData getBeforeBydate(){
        int January = 0;
        int February = 0;
        int March = 0;
        int April = 0;
        int May = 0;
        int June = 0;
        int July = 0;
        int August = 0;
        int September = 0;
        int October = 0;
        int November = 0;
        int December = 0;
        List<JsBeforeUser> beforeBydate = syStatisticalService.getBeforeBydate();

        for (JsBeforeUser bDate : beforeBydate) {
            String substring = bDate.getCreateDate().substring(5, 7);
            if(substring.equals("01")){
                January++;
            }else if(substring.equals("02")){
                February++;
            }else if(substring.equals("03")){
                March++;
            }else if(substring.equals("04")){
                April++;
            }else if(substring.equals("05")){
                May++;
            }else if(substring.equals("06")){
                June++;
            }else if(substring.equals("07")){
                July++;
            }else if(substring.equals("08")){
                August++;
            }else if(substring.equals("09")){
                September++;
            }else if(substring.equals("10")){
                October++;
            }else if(substring.equals("11")){
                November++;
            }else if(substring.equals("12")){
                December++;
            }
        }
        List list = new ArrayList();
        list.add(January);
        list.add(February);
        list.add(March);

        list.add(April);
        list.add(May);
        list.add(June);

        list.add(July);
        list.add(August);
        list.add(September);

        list.add(October);
        list.add(November);
        list.add(December);

        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器出错了");
    }

    //根据创建时间查询后端用户
    @RequestMapping(value = "/getUserByDate")
    @ResponseBody
    public JsonData getUserByDate(){
        int January = 0;
        int February = 0;
        int March = 0;
        int April = 0;
        int May = 0;
        int June = 0;
        int July = 0;
        int August = 0;
        int September = 0;
        int October = 0;
        int November = 0;
        int December = 0;
        List<User> userByDate = syStatisticalService.getUserByDate();
        for (User uDate : userByDate) {
            String substring = uDate.getRegisterDate().substring(5, 7);
            if(substring.equals("01")){
                January++;
            }else if(substring.equals("02")){
                February++;
            }else if(substring.equals("03")){
                March++;
            }else if(substring.equals("04")){
                April++;
            }else if(substring.equals("05")){
                May++;
            }else if(substring.equals("06")){
                June++;
            }else if(substring.equals("07")){
                July++;
            }else if(substring.equals("08")){
                August++;
            }else if(substring.equals("09")){
                September++;
            }else if(substring.equals("10")){
                October++;
            }else if(substring.equals("11")){
                November++;
            }else if(substring.equals("12")){
                December++;
            }
        }
        List list = new ArrayList();
        list.add(January);
        list.add(February);
        list.add(March);

        list.add(April);
        list.add(May);
        list.add(June);

        list.add(July);
        list.add(August);
        list.add(September);

        list.add(October);
        list.add(November);
        list.add(December);

        return list != null ? JsonData.buildSuccess(list) : JsonData.buildError("服务器出错了");
    }


    //查询所有商品以及评论数量
    @RequestMapping(value = "/getCommodityReview")
    @ResponseBody
    public JsonData getCommodityReview(){
        List<JsComment> commodityReview = syStatisticalService.getCommodityReview();
        return commodityReview != null ? JsonData.buildSuccess(commodityReview) : JsonData.buildError("服务器出错了");
    }

    //查询所有课程以及评论数量
    @RequestMapping(value = "/getCourseReview")
    @ResponseBody
    public JsonData getCourseReview(){
        List<JsComment> courseReview = syStatisticalService.getCourseReview();
        return courseReview != null ? JsonData.buildSuccess(courseReview) : JsonData.buildError("服务器出错了");
    };

    //查询所有微圈以及评论数量
    @RequestMapping(value = "/getCircleReview")
    @ResponseBody
    public JsonData getCircleReview(){
        List<JsComment> circleReview = syStatisticalService.getCircleReview();
        return circleReview != null ? JsonData.buildSuccess(circleReview) : JsonData.buildError("服务器出错了");
    }

}
